{% extends 'base.html' %}

{% block head %}
<link rel="stylesheet" href="../static/css/article.css">
<style>
    @font-face {
        font-family: 'MaobiFont'; /* 字体名称 */
        src: url('../static/fonts/FZQiTi-S14S.TTF') format('truetype');
    }

    .post-title {
        font-size: 24px;
        color: #e56244;
    }

    .post-favorite {
        text-align: right;
        font-weight: bold;
    }

    .post-favorite .animate {
        animation: pulse 0.5s ease;
    }

    .post-info {
        margin-top: 20px;
        border-bottom: solid 1px #cccccc;
        line-height: 60px;
    }

    .post-info span {
        display: inline-block;
        padding-right: 20px;
    }

    .post-content {
        margin-top: 30px;
        line-height: 1.75;
        word-break: break-all;
        word-wrap: break-word;
        text-align: justify;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
        color: #333;
        font-size: 17px;
        /* 字间距，微调可使排版更松散 */
        letter-spacing: 0.02em;
        /* 段落下边距 */
        margin-bottom: 1.5em;
    }
    .post-content img{
        max-width: 100%;
        height: auto;
        display: block; /* 可选：防止图片下方出现多余空隙 */
    }

    .post-content .readall {
        margin: 20px 0;
        text-align: center;
    }

    .post-content .readall button {
        height: 45px;
        background-color: #337AB7;
        border: 0;
        border-radius: 5px;
        color: white;
        font-weight: bold;
    }


    .post-nav {
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        margin: 30px 0;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); /* 微妙阴影 */
        padding: 20px 50px;
        background: #fff; /* 纯白背景 */
        transition: box-shadow 0.3s; /* 悬停效果 */
    }

    .post-nav div {
        line-height: 40px;
    }


</style>
{% endblock head %}


{% block bodyMiddle %}

<div class="col-sm-9 col-12" style="padding: 0">
    <!--文章内容-->
    <div class="article-panel" >
        <div class="col-12 row" style="margin:0">
            <div class="col-9 post-title">
                {{article.headline}}
            </div>
            <div class="col-3 post-favorite">
                <div id="favorite-btn">
                    <!--                    <label-->
                    <!--                    style="cursor: pointer;color: #e56244"><i class="fa fa-heart"-->
                    <!--                                                              aria-hidden="true"></i>&nbsp;已收藏</label>-->
                </div>
            </div>
            <div class="col-12 post-info">
                <span>作者：{{article.nickname}}</span>
                <span>类别：{{article_type[article.type | string]}}</span>
                <span>日期：{{article.createtime}}</span>
                <span>阅读：{{article.readcount}}次</span>
                {% if article.credit > 0 %}
                <span>所需积分：{{article.credit}}</span>
                {% endif %}
            </div>
            <div class="col-12 post-content" id="article_content">
                {{article.content | safe}}
                {% if article.credit > 0 and article.nickname!=session.nickname and paid_flag==False %}
                <div class="readall">
                    <button class="col-sm-10 col-12" onclick="readAll()">
                        <span class="oi oi-data-transfer-download" aria-hidden="true"></span>
                        阅读全文（消耗积分：{{article['credit']}} 分）
                    </button>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
    <!--文章底部导航-->
    <div class="post-nav">
        <div style="color: #2b3035;font-family: 'MaobiFont';font-size: 17px">阅微札记<br>
            晨昏探幽赜，万象入毫端。星斗罗胸次，云涛生砚澜。苔花绽古壁，芥子纳坤乾。积霭成天瀑，<br>
            涓滴汇海湍。扪虱论寰宇，骑鲸啸宙巅。展卷惊神鬼，长歌破冥渊。何惧星霜改，光华照岁寒。
        </div>
        <div>版权所有，转载文章请注明出处。</div>
        <div><a href="/article/{{pre_next_dict.prev_id}}">上一篇：{{pre_next_dict.prev_headline}}</a></div>
        <div><a href="/article/{{pre_next_dict.next_id}}">下一篇：{{pre_next_dict.next_headline}}</a></div>
    </div>
    <!--文章评论区-->
    <div class="post-comment">
        <div style="color: #252933;font-size: 18px;font-weight: 600;line-height: 30px;margin-bottom: 20px">评论</div>
        <div class="col-12 row">
            <div class="col-1"><img src="../static/img/avatar/{{session.avatar}}"
                                    style="width: 45px;margin-top: 5px;border-radius: 50%"></div>
            <div class="col-11 form-floating">
                <textarea class="form-control" id="floatingTextarea"
                          style="height: 100px;width: 750px;padding-top: 8px"></textarea>
            </div>
        </div>
        <div class="col-12 clearfix">
            <div style="float: right;padding-right: 80px;padding-top: 10px">
                <button class="btn btn-primary" id="comment-btn" onclick="addcomment('{{article.articleid}}')">发表评论
                </button>
            </div>
        </div>
        <div class="reddit col-12">
            <div class="img-container">
                <!-- 显示最新-->
                <div class="comment-zone">
                    <div style="margin-bottom: 20px;padding-bottom:10px;border-bottom: #dddddd solid 1px"><label
                            class="refresh-btn" id="refreshBtn">最新</label>
                        <label class="comments-count">评论 <span id="count">0</span> 条</label></div>
                    <div>
                        <div id="comments-list"></div>
                        <div class="load-more-container">
                            <button id="loadMoreBtn" class="load-more-btn">加载更多评论</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    // 需要消耗积分的文章点击查看剩余的文章
    function readAll() {
        var params = 'articleid={{article.articleid}}&&position={{position}}';
        // console.log(params);
        $.post('/readall', params, data => {
            if (data == 'not_enough_credit') {
                alert('积分不足！')
            } else {
                $("#article_content").append(data);
                $(".readall").hide();
            }
        })
    }

    // 文章收藏和取消收藏
    document.addEventListener('DOMContentLoaded', function () {
        //载入收藏的按钮和功能
        loadFavorite()
        //-----------------
        // 动态置入评论区评论
        const commentsList = document.getElementById('comments-list');
        const refreshBtn = document.getElementById('refreshBtn');
        const loadMoreBtn = document.getElementById('loadMoreBtn');
        const countElement = document.getElementById('count');
        // 当前用户
        const currentUser = '{{session.username}}';

        // 分页相关变量
        let currentPage = 1;
        const commentsPerPage = 10;
        let allComments = [];

        // 获取评论数据
        function fetchComments() {
            commentsList.innerHTML = '<div class="loading"> 正在加载评论...</div>';
            loadMoreBtn.disabled = true;
            params = 'articleid=' + '{{article.articleid}}';
            fetch('/api/replies', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: params,
            }).then(response => {
                if (!response.ok) {
                    throw new Error('网络响应不正常');
                } else {
                    return response.json();
                }
            })
                .then(commentsData => {
                    processCommentsData(commentsData);
                }).catch(error => {
                console.error('Error:', error)
                showError(error)
            })
        }

        // 处理评论数据
        function processCommentsData(commentsData) {
            // 将嵌套结构的评论转换为扁平数组（只提取顶级评论）
            allComments = [];
            for (const commentId in commentsData) {
                if (commentsData.hasOwnProperty(commentId)) { //这是一个安全检查，确保我们只处理对象自身的属性，而不包括从原型链继承的属性
                    allComments.push(commentsData[commentId]);//将一层评论的json表放到allcomments中去
                }
            }

            // 按时间排序（最新的在前面）
            allComments.sort((a, b) => new Date(b.createtime) - new Date(a.createtime));

            // 计算评论总数（包括回复）,并在页面中通过textContent显示
            const totalComments = countComments(commentsData);
            countElement.textContent = totalComments;

            // 重置分页
            currentPage = 1;

            // 渲染评论
            renderComments();
        }

        // 计算评论总数（包括回复）
        function countComments(comments) {
            let count = 0;
            for (const commentId in comments) {
                if (comments.hasOwnProperty(commentId)) {
                    count++; // 计数当前评论
                    const comment = comments[commentId];
                    // 递归计数回复
                    if (comment.replies && Object.keys(comment.replies).length > 0) {
                        count += countComments(comment.replies);
                    }
                }
            }
            return count;
        }

        // 渲染评论列表
        function renderComments() {
            // 清空当前评论列表
            commentsList.innerHTML = '';

            if (allComments.length === 0) {
                commentsList.innerHTML = '<div class="empty">暂无评论，快来抢沙发吧！</div>';
                loadMoreBtn.style.display = 'none';
                return;
            }

            // 计算当前应该显示哪些评论
            const startIndex = 0;
            const endIndex = Math.min(currentPage * commentsPerPage, allComments.length);
            const commentsToShow = allComments.slice(startIndex, endIndex);

            // 渲染评论
            commentsToShow.forEach(comment => {
                const commentElement = createCommentElement(comment, null);
                commentsList.appendChild(commentElement);
            });

            // 更新加载更多按钮状态
            if (endIndex >= allComments.length) {
                loadMoreBtn.disabled = true;
                loadMoreBtn.textContent = '已加载所有评论';
            } else {
                loadMoreBtn.disabled = false;
                loadMoreBtn.textContent = `加载更多评论 (${endIndex}/${allComments.length})`;
            }
        }

        // 创建单个评论元素
        // 创建单个评论元素
        function createCommentElement(comment, parentAuthor) {
            const commentDiv = document.createElement('div');
            commentDiv.className = 'comment';
            commentDiv.id = `comment-${comment.commentid}`;

            // 生成头像（使用作者名首字母）
            // const initial = comment.nickname ? comment.nickname.charAt(0).toUpperCase() : 'U';

            // 格式化时间
            const time = comment.createtime ? new Date(comment.createtime).toLocaleString() : '时间未知';

            // 构建评论内容
            let commentHTML = `
                    <div class="comment-header">
                        <div class="avatar"><img class="avatar" src='../static/img/avatar/${comment.avatar}'></div>
                        <div class="comment-author">${comment.nickname || '匿名用户'}</div>
                        <div class="comment-time">${time}</div>
                    </div>
                `;

            // 如果是回复，显示回复信息（新增）
            if (parentAuthor) {
                commentHTML += `
                        <div class="reply-info">
                            <i class="fas fa-reply reply-icon"></i>
                            回复 @${parentAuthor}
                        </div>
                    `;
            }

            commentHTML += `
                    <div class="comment-content">${comment.content || '无内容'}</div>
                    <div class="comment-actions">
                        <button class="action-btn reply-btn" data-comment-id="${comment.commentid}" data-comment-author="${comment.nickname}">
                            <i class="fas fa-reply"></i> 回复
                        </button>
                        <button class="action-btn like-btn" data-comment-id="${comment.commentid}">
                            <i class="fas fa-thumbs-up"></i> <span>${comment.agreecount || 0}</span>
                        </button>
                        <button class="action-btn dislike-btn" data-comment-id="${comment.commentid}">
                            <i class="fas fa-thumbs-down"></i> <span>${comment.opposecount || 0}</span>
                        </button>
                    </div>
                    <div class="reply-form" id="reply-form-${comment.commentid}">
                        <textarea class="reply-textarea" placeholder="写下您的回复..."></textarea>
                        <div class="reply-actions">
                            <button class="reply-cancel">取消</button>
                            <button class="reply-submit">提交回复</button>
                        </div>
                    </div>
                `;

            commentDiv.innerHTML = commentHTML;

            // 如果有回复，添加展开/折叠按钮和回复容器（修改）
            if (comment.replies && Object.keys(comment.replies).length > 0) {
                const replyCount = countReplies(comment.replies);
                const toggleButton = document.createElement('button');
                toggleButton.className = 'toggle-replies';
                toggleButton.innerHTML = `<i class="fas fa-chevron-down"></i> 查看回复 (${replyCount})`;
                toggleButton.addEventListener('click', function () {
                    const repliesContainer = commentDiv.querySelector('.replies');
                    const icon = this.querySelector('i');

                    if (repliesContainer.classList.contains('expanded')) {
                        repliesContainer.classList.remove('expanded');
                        icon.className = 'fas fa-chevron-down';
                        this.innerHTML = `<i class="fas fa-chevron-down"></i> 查看回复 (${replyCount})`;
                    } else {
                        repliesContainer.classList.add('expanded');
                        icon.className = 'fas fa-chevron-up';
                        this.innerHTML = `<i class="fas fa-chevron-up"></i> 折叠回复 (${replyCount})`;
                    }
                });

                commentDiv.appendChild(toggleButton);

                const repliesContainer = document.createElement('div');
                repliesContainer.className = 'replies';

                // 递归渲染回复（修改：支持无限层级）
                for (const replyId in comment.replies) {
                    if (comment.replies.hasOwnProperty(replyId)) {
                        const reply = comment.replies[replyId];
                        const replyElement = createCommentElement(reply, comment.nickname);
                        repliesContainer.appendChild(replyElement);
                    }
                }

                commentDiv.appendChild(repliesContainer);
            }

            // 添加事件监听
            const replyBtn = commentDiv.querySelector('.reply-btn');
            const likeBtn = commentDiv.querySelector('.like-btn');
            const dislikeBtn = commentDiv.querySelector('.dislike-btn');
            const replyForm = commentDiv.querySelector('.reply-form');
            const cancelBtn = commentDiv.querySelector('.reply-cancel');
            const submitBtn = commentDiv.querySelector('.reply-submit');
            //静态加载评论的初始点赞状态
            if (comment.opinion === 0) {
                likeBtn.classList.remove('liked');
                dislikeBtn.classList.add('disliked');
            } else if (comment.opinion === 1) {
                likeBtn.classList.add('liked');
                dislikeBtn.classList.remove('disliked');
            } else {
                likeBtn.classList.remove('liked');
                dislikeBtn.classList.remove('disliked');
            }

            replyBtn.addEventListener('click', function () {
                const commentId = this.getAttribute('data-comment-id');
                const commentAuthor = this.getAttribute('data-comment-author');

                // 隐藏所有其他回复表单
                document.querySelectorAll('.reply-form').forEach(form => {
                    if (form.id !== `reply-form-${commentId}`) {
                        form.classList.remove('active');
                    }
                });

                // 设置回复文本框的占位符（新增）
                const textarea = replyForm.querySelector('.reply-textarea');
                textarea.placeholder = `回复 @${commentAuthor}...`;

                // 切换当前回复表单
                replyForm.classList.toggle('active');

                // 如果回复表单可见，滚动到它
                if (replyForm.classList.contains('active')) {
                    setTimeout(() => {
                        replyForm.scrollIntoView({behavior: 'smooth', block: 'nearest'});
                    }, 100);
                }
            });

            likeBtn.addEventListener('click', function () {
                const commentId = this.getAttribute('data-comment-id');
                handleLike(commentId, likeBtn, dislikeBtn);
            });

            dislikeBtn.addEventListener('click', function () {
                const commentId = this.getAttribute('data-comment-id');
                handleDislike(commentId, likeBtn, dislikeBtn);
            });

            cancelBtn.addEventListener('click', function () {
                replyForm.classList.remove('active');
            });

            submitBtn.addEventListener('click', function () {
                const textarea = replyForm.querySelector('.reply-textarea');
                const content = textarea.value.trim();
                const commentId = replyBtn.getAttribute('data-comment-id');
                const commentAuthor = replyBtn.getAttribute('data-comment-author');

                if (content) {
                    handleReply(commentId, commentAuthor, content);
                    textarea.value = '';
                    replyForm.classList.remove('active');
                } else {
                    alert('回复内容不能为空！');
                }
            });

            return commentDiv;
        }

        // 渲染回复

        // 计算回复数量（新增）
        function countReplies(replies) {
            let count = 0;
            for (const replyId in replies) {
                if (replies.hasOwnProperty(replyId)) {
                    count++;
                    const reply = replies[replyId];
                    if (reply.replies && Object.keys(reply.replies).length > 0) {
                        count += countReplies(reply.replies);
                    }
                }
            }
            return count;
        }

        // 处理点赞
        function handleLike(commentId, likeBtn, dislikeBtn) {
            // 获取当前点赞和反对数量
            const likeCountElement = likeBtn.querySelector('span');
            const dislikeCountElement = dislikeBtn.querySelector('span');
            let likeCount = parseInt(likeCountElement.textContent);
            let dislikeCount = parseInt(dislikeCountElement.textContent);

            // 发送API请求到后端
            params = 'commentid=' + commentId + '&like=1'+'&articleid='+`{{article.articleid}}`;
            fetch(`/api/like`, {
                method: 'POST',
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                body: params // 1 表示点赞
            }).then(response => {
                if (!response.ok) {
                    throw new Error('点赞失败');
                } else {
                    return response.json();
                }
            }).then(data => {
                // 处理成功响应
                if (data['status'] === 'do-new-opinion') {
                    // 新点赞：点赞数+1
                    likeCountElement.textContent = likeCount + 1;
                    likeBtn.classList.add('liked');
                    dislikeBtn.classList.remove('disliked');
                    console.log(`点赞评论 ${commentId} 成功`);
                } else if (data['status'] === 'cancel-agree') {
                    // 取消点赞：点赞数-1
                    likeCountElement.textContent = likeCount - 1;
                    console.log('点赞取消:', data);
                    likeBtn.classList.remove('liked');
                    dislikeBtn.classList.remove('disliked');
                } else if (data['status'] === 'chang-agree') {
                    // 从反对变为点赞：点赞数+1，反对数-1
                    likeCountElement.textContent = likeCount + 1;
                    dislikeCountElement.textContent = dislikeCount - 1;
                    console.log('变成点赞:', data);
                    likeBtn.classList.add('liked');
                    dislikeBtn.classList.remove('disliked');
                } else if (data['status'] === 'redo-agree-oppose') {
                    // 重新点赞（从反对状态变为点赞）：点赞数+1
                    likeCountElement.textContent = likeCount + 1;
                    console.log('重新点赞:', data);
                    likeBtn.classList.add('liked');
                    dislikeBtn.classList.remove('disliked');
                } else {
                    console.log('点赞失败:', data);
                }
            }).catch(error => {
                console.error('点赞操作出错:', error);
                alert('点赞操作失败，请重试');
            });
        }

        // 处理反对
        function handleDislike(commentId, likeBtn, dislikeBtn) {
            // 发送API请求到后端
            const params = 'commentid=' + commentId + '&like=0'+'&articleid='+`{{article.articleid}}`;

            fetch(`/api/like`, {
                method: 'POST',
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                body: params // 0 表示反对
            })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('反对失败');
                    }
                    return response.json();
                })
                .then(data => {
                    // 获取DOM元素
                    const countElement = dislikeBtn.querySelector('span');
                    const likeCountElement = likeBtn.querySelector('span');

                    // 处理不同状态
                    switch (data.status) {
                        case 'do-new-opinion':
                            likeBtn.classList.remove('liked');
                            dislikeBtn.classList.add('disliked');
                            countElement.textContent = parseInt(countElement.textContent) + 1;
                            console.log(`反对评论 ${commentId} 成功`);
                            break;

                        case 'change-oppose':
                            likeBtn.classList.remove('liked');
                            dislikeBtn.classList.add('disliked');
                            countElement.textContent = parseInt(countElement.textContent) + 1;
                            likeCountElement.textContent = parseInt(likeCountElement.textContent) - 1;
                            console.log('转为反对:', data);
                            break;

                        case 'cancel-oppose':
                            likeBtn.classList.remove('liked');
                            dislikeBtn.classList.remove('disliked');
                            countElement.textContent = parseInt(countElement.textContent) - 1;
                            console.log('取消反对:', data);
                            break;

                        case 'redo-agree-oppose':
                            likeBtn.classList.remove('liked');
                            dislikeBtn.classList.add('disliked');
                            countElement.textContent = parseInt(countElement.textContent) + 1;
                            console.log('重新反对:', data);
                            break;

                        default:
                            console.log('反对失败:', data);
                    }
                })
                .catch(error => {
                    console.error('请求失败:', error);
                    alert('操作失败，请稍后重试');
                });
        }

// 处理回复（修改：添加了commentAuthor参数）
        function handleReply(commentId, commentAuthor, content) {
            // 这里应该发送API请求到后端
            articleId = `{{article.articleid}}`;
            fetch('/api/comments/reply', {
                method: 'POST',
                headers: {'Content-Type': 'application/json'},
                body: JSON.stringify({
                    articleid: articleId,
                    commentid: commentId,
                    content: content,
                })
            }).then(response => {
                if (!response.ok) {
                    throw new Error('网络错误');
                } else {
                    return response.text();  // 解析响应为文本
                }
            }).then(data => {
                // 假设后端返回的是一个字符串，你可以在这里处理这个字符串
                if (data === "add-pass") {
                    console.log(`回复评论 ${commentId} (作者: ${commentAuthor}): ${content}`);
                    window.location.reload();
                } else if (data === "add-fail") {
                    alert("回复失败");
                } else if (data === "add-limit"){
                    alert("今日回复次数受限，请明日再试");
                }else{
                    alert("回复内容要求在2-200字之间")
                }

            }).catch(error => {
                console.error('Error:', error);
                alert('网络未知错误');
            });
        }

        // 显示错误信息
        function showError(error) {
            commentsList.innerHTML = `
                    <div class="error">
                        <p><i class="fas fa-exclamation-circle"></i> 加载评论失败: ${error.message}</p>
                        <p>请检查网络连接或稍后再试</p>
                    </div>
                `;
            console.error('获取评论出错:', error);
        }

        // 加载更多评论
        function loadMoreComments() {
            currentPage++;
            renderComments();
        }

        // 添加事件监听
        refreshBtn.addEventListener('click', fetchComments);
        loadMoreBtn.addEventListener('click', loadMoreComments);

        fetchComments()
    })

    //加载收藏按键
    function loadFavorite() {
        var favorite_btn = document.getElementById('favorite-btn');
        let isFavorited = {{ is_favorited | lower }}
        if (isFavorited) {
            favorite_btn.innerHTML = '<label style="color: #e74c3c;cursor: pointer"><i class="fa fa-heart" aria-hidden="true"></i>&nbsp;已收藏</label>';
        } else {
            // console.log(isFavorited)
            favorite_btn.innerHTML = '<label style="color: #13653f;cursor: pointer"><i class="fa fa-heart-o" aria-hidden="true"></i>&nbsp;收藏本文</label>';
        }
        // 处理收藏按钮点击
        favorite_btn.addEventListener('click', function () {
            // 添加动画效果
            this.classList.add('animate');
            setTimeout(() => {
                this.classList.remove('animate');
            }, 500);
            //发送ajax请求
            fetch('/favorite', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json' // 确保这里设置正确的Content-Type
                },
                body: JSON.stringify({
                    article_id: `{{article.articleid}}`,
                    action: isFavorited ? 'unfavorite' : 'favorite'
                })
            }).then(response => {
                if (!response.ok) {
                    throw new Error('网络错误');
                } else {
                    return response.text()
                }
            }).then(data => {
                console.log(data)
                if (data === 'favorite-pass') {
                    favorite_btn.innerHTML = '<label style="color: #e74c3c;cursor: pointer"><i class="fa fa-heart" aria-hidden="true"></i>&nbsp;已收藏</label>';
                    isFavorited = true
                } else if (data === 'cancel-favorite-pass') {
                    favorite_btn.innerHTML = '<label style="color: #13653f;cursor: pointer"><i class="fa fa-heart-o" aria-hidden="true"></i>&nbsp;收藏本文</label>';
                    isFavorited = false
                } else if (data === 'favorite-fail') {
                    alert('收藏失败！');
                } else if (data === 'cancel-favorite-fail') {
                    alert('取消收藏失败');
                } else {
                    alert('操作失败');
                }
            }).catch(error => {
                console.error('Error:', error);
            })
        })
    }

    //提交新的原始评论
    function addcomment(articleid) {
        var content = document.getElementById('floatingTextarea').value.trim();
        if (content.length < 2 || content.length > 200) {
            alert('错误提示：评论字数请控制在2-200字之间！');
            return false;
        }
        var params = 'articleid=' + articleid + '&content=' + content;
        fetch('/comment', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: params
        }).then(response => response.text())
            .then(data => {
                if (data == 'content-invalid') {
                    alert({title: "错误提示", message: "评论内容在5-1000字之间."});
                } else if (data == 'add-limit') {
                    alert({title: "错误提示", message: "你当天已经用完5条评论的限额."});
                } else if (data == 'add-pass') {
                    window.location.reload();
                } else {
                    alert({title: "错误提示", message: "发表评论出错，请联系管理员."});
                }
            })
    }


</script>

{% include 'include/side_vue.html' %}

{% endblock bodyMiddle %}